/**
 * Copyright (c) 2013 onionframework.org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package org.onionframework.code.action;

import java.util.List;

import javax.annotation.PostConstruct;

import org.onionframework.code.model.Code;
import org.onionframework.code.model.CodeType;
import org.onionframework.code.service.CodeService;
import org.onionframework.code.service.CodeTypeService;
import org.onionframework.faces.extension.ViewAction;
import org.onionframework.faces.web.action.OnionAction;
import org.onionframework.persistence.query.OnionQuery;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author allan
 *
 */
@ViewAction("code.code")
public class CodeAction extends OnionAction<Code> {

	private static final long serialVersionUID = 7418145536302719502L;

	@Autowired private CodeService codeService;
	@Autowired private CodeTypeService codeTypeService;

	protected List<CodeType> types;
	
	@PostConstruct
	public void init(){
		super.setService(this.codeService);
		super.init();
		this.initTypes();
	}
	
	@Override
	protected void initDatas(OnionQuery query){
		super.initDatas(query);
	}
	
	@Override
	public void onEdit(){
	}
	
	@Override
	public void save(){
		super.save();
	}
	
	public void initTypes(){
		this.types = this.codeTypeService.findAll();
	}

	/**
	 * @return the types
	 */
	public List<CodeType> getTypes() {
		return types;
	}
}
